<?xml version="1.0" encoding="UTF-8"?>
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
	xmlns:ui="http://java.sun.com/jsf/facelets"
	xmlns:f="http://java.sun.com/jsf/core"
	xmlns:h="http://java.sun.com/jsf/html"
	xmlns:p="http://primefaces.org/ui"
	template="/WEB-INF/templates/template.xhtml">
	<ui:define name="content">

		<script type="text/javascript"
			src="http://maps.google.com/maps/api/js?sensor=false"></script>
		<script>
var directionsDisplay;
var directionsService = new google.maps.DirectionsService();

function initialize() {
  directionsDisplay = new google.maps.DirectionsRenderer();
  var mapOptions = {
    zoom: 7,
    mapTypeId: google.maps.MapTypeId.ROADMAP,
    center: new google.maps.LatLng(41.850033, -87.6500523)
  };
  var map = new google.maps.Map(document.getElementById('map-canvas'),
      mapOptions);
  directionsDisplay.setMap(map);
  directionsDisplay.setPanel(document.getElementById('directions-panel'));

  var control = document.getElementById('control');
  control.style.display = 'block';
  map.controls[google.maps.ControlPosition.TOP_CENTER].push(control);
}

function calcRoute() {
  var start = document.getElementById('start').value;
  var end = document.getElementById('end').value;
  var request = {
    origin: start,
    destination: end,
    travelMode: google.maps.TravelMode.DRIVING
  };
  directionsService.route(request, function(response, status) {
    if (status == google.maps.DirectionsStatus.OK) {
      directionsDisplay.setDirections(response);
    }
  });
}

google.maps.event.addDomListener(window, 'load', initialize);

    </script>

		<p:panel>
			<p:selectOneMenu id="start" onchange="calcRoute();">
				<f:selectItem itemLabel="chicago, il" itemValue="chicago, il" />
				<f:selectItem itemLabel="st louis, mo" itemValue="st louis, mo" />
			</p:selectOneMenu>

			<p:selectOneMenu id="end" onchange="calcRoute();">
				<f:selectItem itemLabel="amarillo, tx" itemValue="amarillo, tx" />
				<f:selectItem itemLabel="chicago, il" itemValue="chicago, il" />
				<f:selectItem itemLabel="st louis, mo" itemValue="st louis, mo" />
			</p:selectOneMenu>

			<h:form>
				<p:growl id="messages" showDetail="true" life="2000" />

				<p:gmap center="41.381542, 2.122893" zoom="15" type="ROADMAP"
					style="width:600px;height:400px">

					<p:ajax event="stateChange" listener="#{mapBean.onStateChange}"
						update="messages" />
					<p:ajax event="pointSelect" listener="#{mapBean.onPointSelect}"
						update="messages" />

				</p:gmap>
			</h:form>
		</p:panel>

	</ui:define>
</ui:composition>